home *** CD-ROM | disk | FTP | other *** search
/ Programming Sound Cards / Programming Sound Cards.iso / sound_70 / ref.doc < prev    next >
Text File  |  1995-01-01  |  14KB  |  353 lines

  1.  
  2. Rebooting:
  3.  
  4.     40:72h holds 1234h for warm boot, and 4321h (or != 1234h) for cold boot
  5.     jmp to F000:FFF0h
  6.  
  7. -----------------------------------------------------------------------------
  8. Speaker:
  9.     Port 61h  read  (ISA, EISA)
  10.     Bit [7] = Parity check (parity error)
  11.     Bit [6] = Channel check (ISA parity error)
  12.     Bit [5] = Timer 2 output
  13.     Bit [4] = Toggles with each refresh request
  14.     Bit [3] = Channel check enable (enable ISA parity check)
  15.     Bit [2] = Parity check enable (enable parity check)
  16.     Bit [1] = Speaker data enable (Timer 2 output enable)
  17.     Bit [0] = Speaker timer enable (Timer 2 gate enable)
  18.  
  19.     Port 61h  write  (ISA, EISA)
  20.     Bit [7-4] = Reserved
  21.     Bit [3] = Channel check enable (enable ISA parity check)
  22.     Bit [2] = Parity check enable (enable parity check)
  23.     Bit [1] = Speaker data enable (Timer 2 output enable)
  24.     Bit [0] = Speaker timer enable (Timer 2 gate enable)
  25.  
  26.     Port 61h  write  (XT only)
  27.     Bit [7] = 1 Clear keyboard
  28.     Bit [6] = 0 Hold keyboard clock low
  29.     Bit [5] = 0 I/O check enable
  30.     Bit [4] = 0 RAM parity check enable
  31.     Bit [3] = 0 Read low switches
  32.     Bit [2] = Reserved
  33.     Bit [1] = 1 Speaker data enable (Timer 2 output enable)
  34.     Bit [0] = 1 Speaker timer enable (Timer 2 gate enable)
  35.  
  36. -----------------------------------------------------------------------------
  37. 8254 Programmable Interval Timer (PIT)
  38.  
  39.     Counter 0:  System timer, Always on, 1.193MHz, IRQ0
  40.     Counter 1:  Refresh request, Always on, 1.193MHz, Request refresh
  41.     Counter 2:  Speaker frequency, enable speaker, 1.193MHz, Speaker signal
  42.  
  43.     Port 40h  Read/Write    Counter 0
  44.     Port 41h  Read/Write    Counter 1
  45.     Port 42h  Read/Write    Counter 2
  46.     Port 43h  Write/Only    Control register
  47.         Bits [7..6]     Select counter
  48.             00          Counter 0
  49.             01          Counter 1
  50.             10          Counter 2
  51.             11          Read back command
  52.  
  53.         Bits [5..4]     Operation
  54.             00          Latch counter (bits[3..1] are don't care)
  55.             01          Read/Write LSB only
  56.             10          Read/Write MSB only
  57.             11          Read/Write LSB, then MSB
  58.  
  59.         Bits [3..1]     Operating mode selection
  60.             000         Mode 0:  interrupt on terminal count
  61.             001         Mode 1:  hardware triggered one-shot
  62.             x10         Mode 2:  rate generator
  63.             x11         Mode 3:  square-wave generator
  64.             100         Mode 4:  software triggered strobe
  65.             101         Mode 5:  hardware triggered strobe
  66.             xxx         For latch counter operation
  67.  
  68.         Bit [0]         Binary or BCD count down format
  69.             0           Binary (16-bit) count down
  70.             1           BCD count down (four-decades)
  71.             x           For latch counter operation
  72.     Port 43h  Write/Only    Control Register (read-back command)
  73.         Bits [7..6]
  74.             11          Read back command
  75.  
  76.         Bits [5..4]
  77.             0x          latches the state of the CE in COL and COH
  78.             x0          latches status of selected counters into the
  79.                             status register.
  80.  
  81.         Bits [3..0]
  82.             1xx0        Selects counter 2
  83.             x1x0        Selects counter 1
  84.             xx10        Selects counter 0
  85.  
  86.     If status is latched, status is read first through counter read/write
  87.     register.
  88.     If count is latched, the count is read back through counter read/write
  89.     retister, one or two reads depending on how programmed.
  90.  
  91.     Status Byte Latched
  92.         Bit [7]
  93.             0           OUT signal 0 (low)
  94.             1           OUT signal 1 (high)
  95.         Bit [6]
  96.             0           Counter loaded from the counter input registers,
  97.                             count can be read.
  98.             1           Write to the congtrol register or the counter, but
  99.                             the new value has not been loaded into CE.
  100.         Bits [5..4]
  101.             00          Reserved
  102.             01          Read/Write LSByte
  103.             10          Read/Write MSByte
  104.             11          Read/Write LSByte then MSByte
  105.         Bits [3..1]
  106.             000         Mode 0
  107.             001         Mode 1
  108.             010         Mode 2
  109.             011         Mode 3
  110.             100         Mode 4
  111.             101         Mode 5
  112.         Bit [0]
  113.             0           Binary (16-bit) count down
  114.             1           BCD count down (four decades)
  115.  
  116.     1.19318MHz = 4.77273MHz/4.  Typically Counter 0 is set for 0000h (max
  117.     count) 54.925ms.  There are 1573040 tics per day.
  118.  
  119.     This is an example code segment that shows how to speed up the timer
  120.     resolution.  I had no problem with this piece of code on a 486DX2-66,
  121.     on slower machines you may need to slow it down.
  122.  
  123.         ---- cut ----
  124.         .model tiny
  125.         .code
  126.         org 100h
  127.         entry:
  128.             jmp over
  129.         old08vec dd ?
  130.         keeptime dw 0000h
  131.         isr08h:
  132.             inc word ptr cs:[keeptime]
  133.             ; at this point, you have a sped up interrupt
  134.             ; be careful not overload the processor
  135.             cmp cs:[_counter],0FFFFh
  136.             jz notenabled
  137.         notenabled:
  138.             cmp word ptr cs:[keeptime],1000h
  139.             jz handoff
  140.             push ax
  141.             mov al,20h
  142.             out 20h,al
  143.             pop ax
  144.             iret
  145.         handoff:
  146.             mov word ptr cs:[keeptime],0000h
  147.             jmp dword ptr cs:[old08vec]
  148.         over:
  149.             mov ax,3508h
  150.             int 21h
  151.             mov word ptr cs:[old08vec],bx
  152.             mov word ptr cs:[old08vec+2],es
  153.             mov ax,2508h
  154.             mov dx,offset isr08h
  155.             ;tiny no ds
  156.             int 21h
  157.             mov al,10h
  158.             out 40h,al
  159.             mov al,00h
  160.             out 40h,al
  161.             mov ah,00h
  162.             int 16h
  163.             xor al,al
  164.             out 40h,al
  165.             out 40h,al
  166.             mov ax,2508h
  167.             mov dx,word ptr cs:[old08vec]
  168.             mov ds,word ptr cs:[old08vec+2]
  169.             int 21h
  170.             mov ax,4C00h
  171.             int 21h
  172.  
  173.         end entry
  174.         ---- cut ----
  175.  
  176.         The speaker timer (counter 2) can also be used for high resolution
  177.         timing for periods less than 55ms total, using this timer avoids
  178.         the potential harm to the system like Counter 0 or 1.  One
  179.         implementation might be:
  180.  
  181.         Enable timer 2 gate, disable timer 2 output:
  182.         out(61h,01h)
  183.         Set Counter 2 for interrupt on terminal count:
  184.         out(43h,B0h)
  185.         Set MSB to start count and halt counting:
  186.         out(42h,FFh)
  187.         Set LSB to start count and start counting:
  188.         out(42h,FFh)
  189.         Perform task to be timed (with no speaker access)
  190.         Latch count:
  191.         out(43h,C0h)
  192.         Read count:
  193.         LSByte=in(42h)
  194.         MSByte=in(42h)
  195.  
  196. -----------------------------------------------------------------------------
  197. 8259 Programmable Interrupt Controllers (PICs)
  198.  
  199.     Port 20h    write a 20h to clear interrupts (during isr)
  200.                 can write a 60h+irq, but that is not necessary if
  201.                 the PIC is configured for modes that preserve the fully
  202.                 nested structure (which is how you will find it normally)
  203.     Port 21h    read/write, enables and disables irqs 0-7,
  204.                 0 = enabled, 1 = disabled
  205.                 Bit [7]  irq 7
  206.                 Bit [6]  irq 6
  207.                 Bit [5]  irq 5
  208.                 Bit [4]  irq 4
  209.                 Bit [3]  irq 3
  210.                 Bit [2]  irq 2
  211.                 Bit [1]  irq 1
  212.                 Bit [0]  irq 0
  213.  
  214.     Port A0h    write a 20h to clear interrupts (during isr)
  215.                 can write 60h+irq-8, see above (Port 20h)
  216.     Port A1h    read/write, enables and disables irqs 8-15,
  217.                 0 = enable, 1 = disable
  218.                 Bit [7]  irq 15
  219.                 Bit [6]  irq 14
  220.                 Bit [5]  irq 13
  221.                 Bit [4]  irq 12
  222.                 Bit [3]  irq 11
  223.                 Bit [2]  irq 10
  224.                 Bit [1]  irq  9
  225.                 Bit [0]  irq  8
  226.  
  227. --------------------------------------------------------------------------------
  228. 8237 DMA Controller (DMAC)
  229.  
  230.     Port 0000h  DMA Channel 0, Memory address register (r/w)
  231.                 16-bit, LSByte first then MSByte
  232.     Port 0001h  DMA Channel 0, Transfer count register (r/w)
  233.                 16-bit, LSByte first then MSByte
  234.     Port 0002h  DMA Channel 1, Memory address register (r/w)
  235.     Port 0003h  DMA Channel 1, Transfer count register (r/w)
  236.     Port 0004h  DMA Channel 2, Memory address register (r/w)
  237.     Port 0005h  DMA Channel 2, Transfer count register (r/w)
  238.     Port 0006h  DMA Channel 3, Memory address register (r/w)
  239.     Port 0007h  DMA Channel 3, Transfer count register (r/w)
  240.     Port 0008h  DMA Status register (r)
  241.                 bit [7] = 1 Channel 3 request
  242.                 bit [6] = 1 Channel 2 request
  243.                 bit [5] = 1 Channel 1 request
  244.                 bit [4] = 1 Channel 0 request
  245.                 bit [3] = 1 Terminal count on channel 3
  246.                 bit [2] = 1 Terminal count on channel 2
  247.                 bit [1] = 1 Terminal count on channel 1
  248.                 bit [0] = 1 Terminal count on channel 0
  249.     Port 000Ah  DMA Channel 0-3 Mask register (r/w)
  250.                 bits [7..3] = 0 reserved
  251.                 bit [2] = 0 Clear mask bit
  252.                           1 Set mask bit
  253.                 bits [1..0] = 00 Select channel 0
  254.                               01 Select channel 1
  255.                               10 Select channel 2
  256.                               11 Select channel 3
  257.     Port 000Bh  DMA Channel 0-3 Mode register (r/w)
  258.                 bits [7..6] = 00 Demand mode
  259.                               01 Single mode
  260.                               10 Block mode
  261.                               11 Cascade mode
  262.                 bit [5] = 0 Address increment select
  263.                 bit [4] = 0 Autoinitialized
  264.                           1 Non-autoinitialized
  265.                 bits [3..2] = 00 Verify operation
  266.                               01 Write operation
  267.                               10 Read operation
  268.                               11 Reserved
  269.                 bits [1..0] = 00 Select channel 0
  270.                               01 Select channel 1
  271.                               10 Select channel 2
  272.                               11 Select channel 3
  273.     Port 000Ch  DMA Clear Byte Pointer (w)
  274.     Port 000Dh  DMA Master Clear (w)
  275.     Port 000Eh  DMA Clear Mask register (w)
  276.     Port 000Fh  DMA DMA Channel 0-3 Write Mask register (w)
  277.                 bits [7..4] = 0 reserved
  278.                 bit [3] = 0 Unmask channel 3 mask bit
  279.                           1 Set channel 3 mask bit
  280.                           0 Unmask channel 2 mask bit
  281.                           1 Set channel 2 mask bit
  282.                           0 Unmask channel 1 mask bit
  283.                           1 Set channel 1 mask bit
  284.                           0 Unmask channel 0 mask bit
  285.                           1 Set channel 0 mask bit
  286.     Port 0019h  DMA Scratch register (r/w)
  287.     Port 0081h  DMA channel 2, page table address register (r/w)
  288.     Port 0082h  DMA channel 3, page table address register (r/w)
  289.     Port 0083h  DMA channel 1, page table address register (r/w)
  290.     Port 0087h  DMA channel 0, page table address register (r/w)
  291.  
  292.     Notes:
  293.  
  294.     First off, DMA can only access the lower meg (some channels can access
  295.     16M on ATs) which translates to a 20-bit address.  Secondly, DMA cannot
  296.     read/write across a physical page boundary (address with lower 16-bits = 0).
  297.     This also means that DMA cannot transfer more than 64K (actually 65535
  298.     bytes) bytes at a time.  To guarantee no boundary conflicts, many
  299.     programmers allocate 128KBytes, and find the first page boundary within
  300.     that memory space.  Here is an example in Borland 'C' to get 65000 bytes:
  301.  
  302.     ---- cut ----
  303.     unsigned char *data;
  304.     unsigned char *aligned;
  305.     unsigned long aligned_physical;
  306.     ...
  307.         unsigned long physical;
  308.         data=farmalloc(131000L);
  309.         if(data==NULL)
  310.         {
  311.             printf("Memory Allocation Error\n");
  312.             exit(1);
  313.         }
  314.         physical=((unsigned long)FP_OFF(data))+
  315.             (((unsigned long)FP_SEG(data))<<4);
  316.         aligned_physical=physical+0x0FFFFL;
  317.         aligned_physical&=0xF0000L;
  318.         aligned=MK_FP((aligned_physical>>4)&0xFFFF,0);
  319.     ---- cut ----
  320.  
  321.     to have a device read len bytes from the above memory (*aligned) (DMA
  322.         channel 1):
  323.  
  324.     ---- cut ----
  325.     len--;
  326.     outportb(0x0A,0x05);
  327.     outportb(0x0C,0x00);
  328.     outportb(0x0B,0x49);
  329.     outportb(0x02,0);
  330.     outportb(0x02,0);
  331.     outportb(0x83,(aligned_physical>>16)&15);
  332.     outportb(0x03,(unsigned char)(len&0xFF));
  333.     outportb(0x03,(unsigned char)((len>>8)&0xFF));
  334.     outportb(0x0A,0x01);
  335.     ---- cut ----
  336.  
  337.     to have a device write len bytes from the above memory (*aligned) (DMA
  338.       channel 1):
  339.  
  340.     ---- cut ----
  341.     len--;
  342.     outportb(0x0A,0x05);
  343.     outportb(0x0C,0x00);
  344.     outportb(0x0B,0x45);
  345.     outportb(0x02,0);
  346.     outportb(0x02,0);
  347.     outportb(0x83,(aligned_physical>>16)&15);
  348.     outportb(0x03,(unsigned char)(len&0xFF));
  349.     outportb(0x03,(unsigned char)((len>>8)&0xFF));
  350.     outportb(0x0A,0x01);
  351.     ---- cut ----
  352.  
  353.